package com.dylan.channel.v11.channel;


import com.dylan.channel.v11.EventLoop;
import com.dylan.channel.v11.attribute.AttributeMap;
import com.dylan.channel.v11.config.ChannelConfig;
import com.dylan.channel.v11.future.ChannelPromise;
import com.dylan.channel.v11.handler.ChannelPipeline;

import java.net.SocketAddress;

public interface Channel extends AttributeMap, ChannelOutboundInvoker {

    /**
     * Return the {@link EventLoop} this {@link Channel} was registered to.
     * 每个channel都绑定在一个EventLoop中
     */
    EventLoop eventLoop();

    /**
     * @Author: PP-jessica
     * @Description:终于引入了ChannelPipeline
     */
    ChannelPipeline pipeline();

    /**
     * @Author: PP-jessica
     * @Description:这一节课引入channelConfig
     */
    ChannelConfig config();

    boolean isRegistered();

    /**
     * @Author: PP-jessica
     * @Description:终于引入了Unsafe类
     */
    Unsafe unsafe();

    @Override
    Channel read();

    /**
     * 绑定读写操作
     */
    void beginRead();


    interface Unsafe {
        /***
         * @Author dylan
         * @Description: 使用channel注册
         * @Create: 2024/9/12 16:23
         */
        void register(EventLoop eventLoop, ChannelPromise channelPromise);


        /**
         * @Author: PP-jessica
         * @Description:该方法并不在此接口，而是在ChannelOutboundInvoker接口，现在先放在这里
         */
        void bind(SocketAddress localAddress, ChannelPromise promise);

        /**
         * @Author: PP-jessica
         * @Description:该方法并不在此接口，而是在ChannelOutboundInvoker接口，现在先放在这里
         */
        void connect(SocketAddress remoteAddress, final SocketAddress localAddress, ChannelPromise promise);

        void beginRead();

        void write(Object msg, ChannelPromise promise);

        void flush();
    }
}
